﻿@model Associativy.Frontends.Models.IGraphAspect
@using Orchard.ContentManagement

@{
    Script.Require("AssociativyFrontends_Jit").AtFoot();
    Style.Require("AssociativyFrontends_Jit");

    var initialZoomLevel = Model.As<Associativy.Frontends.Models.IEngineConfigurationAspect>().GraphSettings.InitialZoomLevel;
    var maxZoomLevel = Model.ZoomLevelCount - 1;
}

<div id="associativy-jit-associations-canvas-container">
    @Display.GraphZoomSlider(CurrentZoomLevel: initialZoomLevel, MaxZoomLevel: maxZoomLevel)
    <div id="associativy-jit-associations-canvas" class="associativy-graph-canvas">
    </div>
</div>

@Display.AssociativyBadgeOfHonor()

@using (Script.Foot())
{
    <script type="text/javascript">
        (function ($) {
            $.extend(true, {
                associativy: {
                    layout: null,
                    jit: {
                        loadGraph: function (zoomLevel, redraw, isPartialGraph) {
                            var that = this;
                            $.associativy.jit.showLoader();
                            $.post(
                                "@Url.Action("FetchGraph", ViewContext.RouteData.Values)?ZoomLevel=" + zoomLevel + "&" + $("#associativy-search-form").serialize(), 
                                { __RequestVerificationToken: "@Html.AntiForgeryTokenValueOrchard()" },
                                function(graphData) {
                                    if (!redraw) that.layout = $.associativy.jit.draw("associativy-jit-associations-canvas", graphData);
                                    else $.associativy.jit.redraw(that.layout, graphData);

                                    $.associativy.jit.hideLoader();
                                });
                        }
                    }
                }
            });

            $(document).on("stop.AssociativyGraphZoomSlider", function(values) {
                $.associativy.jit.loadGraph(values.ui.value, true);
            });

            $(function() {
                $.associativy.jit.loadGraph(@initialZoomLevel, false);
            });
        })(jQuery);
    </script>
}